//
//  HistoryMainViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/14.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "HistoryMainViewController.h"
#import <JXCategoryTitleView.h>
#import <JXCategoryIndicatorLineView.h>
#import "HistoryExchangeTableViewController.h"
#import "HistoryIncomingTableViewController.h"

@interface HistoryMainViewController ()<JXCategoryViewDelegate>

@property (nonatomic, strong) JXCategoryTitleView *segmentControl;

@end

@implementation HistoryMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = JFMainLocalizedString(@"transactions.Title");
    
    self.view.backgroundColor = UIColorFromHex(0xF4F5F7);
    [self.view addSubview:self.segmentControl];
    
}

- (void)back {
    [self.navigationController popToRootViewControllerAnimated:YES];
}

#pragma mark - WMPageController
- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    if (index < 2) {
        HistoryIncomingTableViewController *vc = [[HistoryIncomingTableViewController alloc]init];
        vc.type = index;
        return vc;
    }
    HistoryExchangeTableViewController *vc = [[HistoryExchangeTableViewController alloc]init];
    vc.type = index;
    return vc;
}

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.segmentControl.titles.count;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectZero;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    return CGRectMake(0, 60, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds) - 60);
}

- (void)pageController:(WMPageController *)pageController didEnterViewController:(nonnull __kindof UIViewController *)viewController withInfo:(nonnull NSDictionary *)info {
    [self.segmentControl selectItemAtIndex:[info[@"index"] intValue]];
}

#pragma mark - JXCategoryViewDelegate
- (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
    self.selectIndex = (int)index;
}

- (JXCategoryTitleView *)segmentControl {
    if (!_segmentControl) {
        _segmentControl = [[JXCategoryTitleView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 55)];
        _segmentControl.backgroundColor = [UIColor whiteColor];
//        _segmentControl.titles = @[@"Incoming", @"Outgoing", @"Exchange", @"Transfer"];
        _segmentControl.titles = @[JFMainLocalizedString(@"transactions.deposit"), JFMainLocalizedString(@"transactions.withdrawal"), JFMainLocalizedString(@"transactions.exchange"), JFMainLocalizedString(@"transactions.transfer")];
        _segmentControl.titleFont = [UIFont fontWithName:@"PingFangSC-Medium" size: 16];
        _segmentControl.titleColor = UIColorFromHex(0x565656);
        _segmentControl.defaultSelectedIndex = self.selectIndex;
        _segmentControl.contentEdgeInsetLeft = _segmentControl.contentEdgeInsetRight = 15;
        _segmentControl.delegate = self;

        JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
        _segmentControl.titleSelectedColor = lineView.indicatorColor = UIColorFromHex(0x708A6A);
        lineView.indicatorWidth = 40;
        _segmentControl.indicators = @[lineView];
    }
    return _segmentControl;
}


@end
